/* save-file-dialog.vala
 *
 * Copyright (C) 2010, 2011  Richard Talbot-Watkins
 * Copyright (C) 2010, 2011  Dave Jeffery
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Authors:
 *  Richard Talbot-Watkins <richtw1@gmail.com>
 * 	Dave Jeffery <david.richard.jeffery@gmail.com>
 */

using Gtk;

/**
 * Save file chooser dialog box.
 *
 * @author Richard Talbot-Watkins <richtw1@gmail.com>
 * @author Dave Jeffery <david.richard.jeffery@gmail.com>
 * @version 2011.0109
 * @since 0.1
 */    
private class BeebSpriter.SaveFileDialog : FileChooserDialog {
	/**
	 * Constructor for the save file dialog box.
	 *
	 * @param file the current path and filename of the file for Save or
	 * 			just current path for Save As...
	 * @param title Title displayed on the file chooser dialog box.
	 * @param filters An array of file filters to apply to file chooser.
	 */ 
	public SaveFileDialog (File file, string title, 
											FileFilter[]? filters = null) {
		action = FileChooserAction.SAVE;
		add_button (STOCK_CANCEL, ResponseType.CANCEL);
		add_button (STOCK_SAVE, ResponseType.ACCEPT);
		set_default_response (ResponseType.ACCEPT);

		foreach (var filter in filters) {
			add_filter (filter);
		}

		this.title = title;

		if (file.query_file_type (0) == FileType.DIRECTORY) {
			try {
				set_current_folder_file (file);
			} catch (Error e) {
				stderr.printf ("%s\n", e.message);
			}
		} else {
			try {
				set_file (file);
			} catch (Error e) {
				stderr.printf ("%s\n", e.message);
			}
			set_current_name(file.get_basename ());
		}		
	}
}
